package org.wendu.wdoa.emp.dao;

import org.apache.ibatis.annotations.*;
import org.wendu.wdoa.common.page.PageParam;
import org.wendu.wdoa.emp.dto.EmpDto;
import org.wendu.wdoa.emp.dto.EmpQueryDto;
import org.wendu.wdoa.emp.dto.MgrDto;
import org.wendu.wdoa.emp.dto.UserDto;
import org.wendu.wdoa.emp.model.Employee;

import java.util.List;

@Mapper
public interface EmployeeDao {

    //@Select("select e.*,d.d_name from t_emp e left join t_dep d on e.d_id=d.d_id")
    public List<Employee> findEmpList(PageParam pageParam);
    @Delete("delete from t_emp where e_id = #{id}")
    void deleteById(String e_id);
    @Select("select count(e_id) from t_emp where e_id = #{id}")
    boolean findExistsId(String e_id);
    @Insert("insert into t_emp(e_id,e_name,e_sex,e_birth,d_id) values(#{e_id},#{e_name},#{e_sex},#{e_birth},#{d_id})")
    void insertEmp(EmpDto empDto);
    @Select("select lpad(ifnull(max(convert(e_id,unsigned)),0)+1,5,'0') from t_emp")
    String findNewId();
    @Update("update t_emp set e_name=#{e_name},e_sex=#{e_sex},e_birth=#{e_birth},d_id=#{d_id} where e_id=#{e_id}")
    void updateEmp(Employee employee);
    @Insert("insert into t_user(u_id,u_name,u_pwd) values(#{u_id},#{u_name},#{u_pwd})")
    void insertEmpUser(UserDto empDto);

    @Delete("delete from t_user where u_id = #{e_id}")
    void deleteEmpUser(String e_id);

    @Insert("insert into t_mgr(mgr_id,e_id,d_id) values(#{mgr_id},#{e_id},#{d_id})")
    void insertEmpMgr(MgrDto mgrDto);
    @Select("select ifnull(max(convert(mgr_id,unsigned)),0)+1 from t_mgr")
    Integer findMgrNewId();

    @Select("select count(e_id) from t_mgr where d_id = #{d_id}")
    boolean findExistMgr(Integer d_id);

    @Delete("delete from t_mgr where e_id=#{e_id} ")
    void deleteMgrEmp(String e_id);

    @Select("select e_id from t_mgr where d_id=#{d_id}")
    String findMgreid(Integer d_id);
}
